const { screen } = require('electron')
const EventEmitter = require('events')
const { robotMouseDown, robotKeyTap} = require('./robot.js')
const keycode = require('keycode')

const robotHandle = new EventEmitter()

robotHandle.on('mousedown', (data) => {
    const { width: screenWidth, height: screenHeight } = screen.getPrimaryDisplay().size
    robotMouseDown({
        ...data,
        screenWidth,
        screenHeight
    })
})
robotHandle.on('keydown', (e) => {
    // console.log(e)
    let modified = []
    e.altKey && modified.push('alt')
    e.ctrlKey && modified.push('control')
    e.metaKey && modified.push('command')
    e.shiftKey && modified.push('shift')
    // 部分key还需要处理，如left command、page down、control等
    // console.log(keycode(e.keyCode), modified)

    robotKeyTap(keycode(e.keyCode), modified)
})


module.exports = robotHandle